using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class TestComp : MonoBehaviour
{
    // Start在第一个帧更新之前被调用
    void Start()
    {
        int testCount = 1000000;//定义测试的次数
        //using (new YiWatch("GetComponent<>", testCount))
        //{
        //    for (int i = 0; i < testCount; i++)
        //    {
        //        GetComponent<TestComp>();
        //    }
        //}
        //using (new YiWatch("GetComponent(typeof(T))", testCount))
        //{
        //    for (int i = 0; i < testCount; i++)
        //    {
        //        GetComponent(typeof(TestComp));
        //    }
        //}
        //using (new YiWatch("GetComponent(string)", testCount))
        //{
        //    for (int i = 0; i < testCount; i++)
        //    {
        //        GetComponent("TestComp");
        //    }
        //}

        //using (new YiWatch("GameObject.Find", testCount))
        //{
        //    for (int i = 0; i < testCount; i++)
        //    {
        //        GameObject.Find("TestComp").GetComponent<TestComp>();
        //    }
        //}

        //using (new YiWatch("FindObjectOfType", testCount))
        //{
        //    for (int i = 0; i < testCount; i++)
        //    {
        //        FindObjectOfType<TestComp>();
        //    }
        //}

        //using (new YiWatch("Defind.GetTopObject", testCount))
        //{
        //    for (int i = 0; i < testCount; i++)
        //    {
        //        //Defind.GetTopObject<TestComp>("TestComp");
        //    }
        //}
    }

    private void Update()
    {
        if (!Input.GetMouseButtonDown(0))
            return;
        Ray2D ray = new Ray2D(Input.mousePosition, Vector2.up);
        var hit = Physics2D.Raycast(new Vector2(ray.origin.x, ray.origin.y), Vector2.up);
        if (hit.collider != null)
            Debug.Log(hit.collider.gameObject.name);
        //hit.collider.gameObject.transform.position = ray.origin;
    }
}
